var t = require("../../../@babel/runtime/helpers/objectSpread2"), a = getApp();

Page({
    data: {
        active: 0,
        selected: {},
        isLoadMore: !0,
        usable_name: "",
        tabOptions: [ {
            isLoadMore: !0,
            page: 1,
            total_page: 0,
            list: [],
            url: "plugin.task-package.frontend.bag.get-list",
            othderJson: {},
            name: "任务商城"
        }, {
            isLoadMore: !0,
            page: 1,
            total_page: 0,
            list: [],
            url: "plugin.task-package.frontend.record.get-list",
            othderJson: {
                status: 1
            },
            name: "运行中"
        }, {
            isLoadMore: !0,
            page: 1,
            total_page: 0,
            list: [],
            url: "plugin.task-package.frontend.record.get-list",
            othderJson: {
                status: 2
            },
            name: "已过期"
        } ]
    },
    onLoad: function(t) {
        this.initData(), this.getData();
    },
    onReady: function() {
        wx.setNavigationBarColor({
            frontColor: "#ffffff",
            backgroundColor: "#FF8924",
            animation: {
                duration: 400,
                timingFunc: "easeIn"
            }
        }), wx.setNavigationBarTitle({
            title: "普法任务"
        });
    },
    initData: function() {
        this.setData({
            active: 0,
            isLoadMore: !0,
            tabOptions: [ {
                isLoadMore: !0,
                page: 1,
                total_page: 0,
                list: [],
                url: "plugin.task-package.frontend.bag.get-list",
                othderJson: {},
                name: "任务商城"
            }, {
                isLoadMore: !0,
                page: 1,
                total_page: 0,
                list: [],
                url: "plugin.task-package.frontend.record.get-list",
                othderJson: {
                    status: 1
                },
                name: "运行中"
            }, {
                isLoadMore: !0,
                page: 1,
                total_page: 0,
                list: [],
                url: "plugin.task-package.frontend.record.get-list",
                othderJson: {
                    status: 2
                },
                name: "已过期"
            } ]
        });
    },
    toMyTask: function() {
        wx.navigateTo({
            url: "/packageI/taskPackage/taskPackageMy/taskPackageMy"
        });
    },
    tapSelectChange: function(t) {
        var a = t.currentTarget.dataset.item;
        this.setData({
            selected: a
        });
    },
    tapTask: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageI/taskPackage/task/task?id=" + a
        });
    },
    getData: function() {
        var e = this;
        if (a._isTextEmpty(this.data.tabOptions[this.data.active].list)) {
            var s = t(t({}, this.data.tabOptions[this.data.active].othderJson), {}, {
                page: 1
            });
            a._getNetWork({
                url: a.getNetAddresss(this.data.tabOptions[this.data.active].url),
                data: s,
                success: function(t) {
                    var a = t.data;
                    if (1 == a.result) {
                        var s = a.data;
                        e.data.tabOptions[e.data.active].list = s.data || [], e.data.tabOptions[e.data.active].total_page = s.last_page, 
                        e.data.tabOptions[e.data.active].isLoadMore = !0, e.setData({
                            tabOptions: e.data.tabOptions,
                            isLoadMore: !0,
                            usable_name: s.usable_name ? s.usable_name : "可用爱心值"
                        }), 0 == e.data.active && e.setData({
                            selected: e.data.tabOptions[0].list[0]
                        }), console.log(e.data.tabOptions, "ddddddddd");
                    }
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        } else this.setData({
            isLoadMore: this.data.tabOptions[this.data.active].isLoadMore
        });
    },
    getMoreData: function() {
        var e = this;
        if (this.data.tabOptions[this.data.active].isLoadMore = !1, this.setData({
            isLoadMore: !1,
            tabOptions: this.data.tabOptions
        }), !(this.data.tabOptions[this.data.active].page >= this.data.tabOptions[this.data.active].total_page)) {
            this.data.tabOptions[this.data.active].page = this.data.tabOptions[this.data.active].page + 1, 
            this.setData({
                tabOptions: this.data.tabOptions
            });
            var s = this.data.tabOptions[this.data.active].page, i = t(t({}, this.data.tabOptions[this.data.active].othderJson), {}, {
                page: s
            });
            a._getNetWork({
                url: a.getNetAddresss(this.data.tabOptions[this.data.active].url),
                data: i,
                success: function(t) {
                    var a = t.data;
                    if (1 == a.result) {
                        var s = a.data;
                        e.data.tabOptions[e.data.active].isLoadMore = !0, e.data.tabOptions[e.data.active].list = e.data.tabOptions[e.data.active].list.concat(s.data), 
                        e.data.tabOptions[e.data.active].total_page = s.last_page, e.setData({
                            isLoadMore: !0,
                            tabOptions: e.data.tabOptions
                        });
                    }
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    exchang: function() {
        var t = this;
        this.data.selected.id ? wx.showModal({
            title: "",
            content: "是否确定用".concat(this.data.selected.love_amount).concat(this.data.usable_name, "兑换该任务包"),
            complete: function(e) {
                e.confirm && a._getNetWork({
                    url: a.getNetAddresss("plugin.task-package.frontend.record.exchange-bag"),
                    data: {
                        id: t.data.selected.id
                    },
                    success: function(a) {
                        var e = a.data;
                        wx.showModal({
                            content: e.msg,
                            showCancel: !1,
                            complete: function(a) {
                                a.confirm && 1 == e.result && (t.initData(), t.getData());
                            }
                        });
                    }
                });
            }
        }) : wx.showToast({
            title: "请选择需要兑换的任务"
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore && this.getMoreData();
    },
    onShareAppMessage: function() {},
    onChange: function(t) {
        console.log(t, "ddddddddddddddddd"), this.setData({
            active: t.detail.index
        }), this.getData();
    }
});